class NumArray {
    private int[] preSum;
    public void NumArray(int[] nums) {
        preSum = new int[nums.length];
        preSum[0] = 0;
        for(int i = 1;i < preSum.length;i++){
            preSum[i] = preSum[i-1] + nums[i];
        }
    }
    public int sumRange(int left, int right) {
        return preSum[right]-preSum[left];
    }
}

